package com.ror.domain;

import java.awt.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;

//席位，不一定用来坐人
public enum Seat {
    LEFT(new Point(50, 100), true, 0, 10),
    //中席，也是主视角的席位
    MIDDLE(new Point(200,470), true, 20, 0),
    RIGHT(new Point(700,100), true, 0, 10),
    //底牌席
    HAND(new Point(220,50), false, 75, 0),
    //牌河席，用来放玩家打出的牌
    CENTER(new Point(200,300), false, 0, 0),
    ;

    //已经有人坐的席位
    public static final ArrayList<Seat> occupiedSeats = new ArrayList<>();
    //基准位置，一般是头一张牌放的位置
    private final Point baseLocation;
    //是否坐人
    public final boolean isSittable;
    //是否有人坐
    private boolean isOccupied = false;
    //放在席上的牌
    private final ArrayList<Poker> cards = new ArrayList<>();
    //叠放卡牌时每张牌的偏移量
    private final int offsetX;
    private final int offsetY;

    Seat(Point baseLocation, boolean isSittable, int offsetX, int offsetY) {
        this.baseLocation = baseLocation;
        this.isSittable = isSittable;
        this.offsetX = offsetX;
        this.offsetY = offsetY;
    }

    //入席
    public void sit() {
        isOccupied = true;
        occupiedSeats.add(this);
    }

    //离席
    public void off() {
        isOccupied = false;
        occupiedSeats.remove(this);
    }

    //进牌
    public boolean addCard(Poker card) {
        return cards.add(card);
    }

    //出牌
    public boolean removeCard(Poker card) {
        return cards.remove(card);
    }

    //查牌
    public Poker getCard(int index) {
        return cards.get(index);
    }

    //查所有牌
    public ArrayList<Poker> getCards() {
        return cards;
    }

    //理牌
    public void sortCards() {
        Collections.sort(cards);
    }

    public Point getBaseLocation() {
        return baseLocation;
    }

    public boolean isOccupied() {
        return isOccupied;
    }

    public int getOffsetX() {
        if (this == CENTER) return new Random().nextInt(20);
        return offsetX;
    }

    public int getOffsetY() {
        if (this == CENTER) return new Random().nextInt(20);
        return offsetY;
    }
}
